package com.abou.mvc.format.impl;

import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.springframework.web.servlet.support.RequestContext;

/**
 * The string formatter
 * 
 * @author khalid
 */
public class CommonsMultipartFileFormatter extends
    ATypeFormatterImpl<CommonsMultipartFile> {
  
  @Override
  public boolean isEmpty(Object value) {

    boolean isEmpty = super.isEmpty(value);
    
    if (!isEmpty && supports(value)) {
      
      isEmpty = StringUtils.isBlank(((String) value).trim());
    }
    
    return isEmpty;
  }
  
  @Override
  protected String formatForType(CommonsMultipartFile value, Locale locale,
      HttpServletRequest request, RequestContext requestContext,
      boolean textOnly) {

    return value.getOriginalFilename();
  }
}
